/**
 * 
 */
package com.apinoo.users.domain;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * @author Alejandro Pino Oreamuno
 *
 */
@Entity
@Table(name = "users")
public class User implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id 
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name = "id_user", unique = true, nullable = false)
	private long idUser;
	
	@Column(name = "username", unique = true, nullable = false)
	private String username;
	
	@Column(name = "password", nullable = false)
	private String password;
	
	@Column(name = "email", unique = true, nullable = false)
	private String email;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.user", cascade = CascadeType.ALL)
	private List<UserGroup> listUserGroup = new ArrayList<UserGroup>();
	
//	@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
//	private List<Login> logins = new ArrayList<Login>();

	@Column(name = "created_date", nullable = false)
	private Timestamp createdDate;
	
	@Column(name = "modified_date")
	private Timestamp modifiedDate;
	
	@Column(name = "enabled", nullable = false)
	private boolean enabled;
	
	@ManyToOne(cascade={CascadeType.ALL})
	@JoinColumn(name="created_by")
	private User createdBy;
	
	@OneToMany(mappedBy="createdBy")
	private List<User> listUsersCreated = new ArrayList<User>();
	
	@ManyToOne(cascade={CascadeType.ALL})
	@JoinColumn(name="modified_by")
	private User modifiedBy;
	
	@OneToMany(mappedBy="modifiedBy")
	private List<User> listUsersModified = new ArrayList<User>();

	public long getIdUser() {
		return idUser;
	}

	public void setIdUser(long idUser) {
		this.idUser = idUser;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public List<UserGroup> getListUserGroup() {
		return listUserGroup;
	}

	public void setListUserGroup(
			List<UserGroup> listUserGroup) {
		this.listUserGroup = listUserGroup;
	}

	public Timestamp getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Timestamp createdDate) {
		this.createdDate = createdDate;
	}

	public Timestamp getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(Timestamp modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public User getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(User createdBy) {
		this.createdBy = createdBy;
	}

	public List<User> getListUsersCreated() {
		return listUsersCreated;
	}

	public void setListUsersCreated(List<User> listUsersCreated) {
		this.listUsersCreated = listUsersCreated;
	}

	public User getModifiedBy() {
		return modifiedBy;
	}

	public void setModifiedBy(User modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	public List<User> getListUsersModified() {
		return listUsersModified;
	}

	public void setListUsersModified(List<User> listUsersModified) {
		this.listUsersModified = listUsersModified;
	}

	@Override
	public String toString() {
		return "User [idUser=" + idUser + ", modifiedBy=" + modifiedBy + "]";
	}
	
}
